package cn.pconline.autoclub.service;

import java.util.List;

import org.gelivable.dao.GeliDao;
import org.gelivable.dao.GeliOrm;
import org.gelivable.dao.SqlBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;

import cn.pconline.autoclub.entity.InviteMember;

public class InviteMemberService {
	private static final Logger log = LoggerFactory.getLogger(InviteMemberService.class);
    @Autowired
    private GeliOrm geliOrm;
    @Autowired
    private GeliDao geliDao;

    public long createInviteMember(InviteMember entity){
    	return geliDao.create(entity);
    }
    
    /**
     * 根据邀请id 获取邀请记录
     * @param inviteId
     * @return
     */
    public List<InviteMember> listByInviteId(long inviteId){
    	if (inviteId<=0) return null;
    	SqlBuilder sql = new SqlBuilder();
    	sql.appendSql(" select invite_member_id from ").appendSql(geliOrm.getTableName(InviteMember.class)).appendSql(" where 1=1 ");
    	sql.appendSql(" and invite_id = ").appendValue(inviteId);
    	
    	try {
    		List<InviteMember> list = geliDao.list(InviteMember.class, sql.getSql(),sql.getValues());
    		return list;
        }
        catch( EmptyResultDataAccessException e ) {
        	log.info("the id {} has a empty collection in InviteMember",inviteId);
	        return null;
        }
    	
    	
    }
}
